/*
===========================================================================
This source file is part of DyLab (Dynamic Laboratory)
For the latest info, see http://dylab.googlecode.com

Copyright (c) 2006-2008 Lukas Krejci
(krejci.lukas@volny.cz)

This file is part of DyLab.

    DyLab is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DyLab is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DyLab.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

//===========================================================================================
#include <dylab/utils/math/Matrix3x3.h>

//===========================================================================================
const dylab::Matrix3x3 dylab::Matrix3x3::ZERO(Math::ZERO, Math::ZERO, Math::ZERO,
											  Math::ZERO, Math::ZERO, Math::ZERO,
											  Math::ZERO, Math::ZERO, Math::ZERO);
const dylab::Matrix3x3 dylab::Matrix3x3::IDENTITY(Math::ONE,  Math::ZERO, Math::ZERO,
												  Math::ZERO, Math::ONE,  Math::ZERO,
												  Math::ZERO, Math::ZERO, Math::ONE);

//-----------------------------------------------------------------------------
void dylab::Matrix3x3::buildFromAxisAndAngle(const Vector3 & _axis, real_t _radians)
{
	real_t sinrad = Math::sin(_radians);
    real_t cosrad = Math::cos(_radians);    
    real_t oneMinusCosRad = DYLAB_R(1.0) - cosrad;

    real_t axx = _axis.mX * _axis.mX;
    real_t ayy = _axis.mY * _axis.mY;
    real_t azz = _axis.mZ * _axis.mZ;
    real_t axyo = _axis.mX * _axis.mY * oneMinusCosRad;
    real_t axzo = _axis.mX * _axis.mZ * oneMinusCosRad;
    real_t ayzo = _axis.mY * _axis.mZ * oneMinusCosRad;
    real_t axs = _axis.mX * sinrad;
    real_t ays = _axis.mY * sinrad;
    real_t azs = _axis.mZ * sinrad;

    mE00 = axx * oneMinusCosRad + cosrad;
    mE01 = axyo - azs;
    mE02 = axzo + ays;
    mE10 = axyo + azs;
    mE11 = ayy * oneMinusCosRad + cosrad;
    mE12 = ayzo - axs;
    mE20 = axzo - ays;
    mE21 = ayzo + axs;
    mE22 = azz * oneMinusCosRad + cosrad;
}
//-----------------------------------------------------------------------------